//
//  GWPopMenu.m
//  新浪微博
//
//  Created by qianfeng on 16/1/11.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWPopMenu.h"
@interface GWPopMenu()
@property (nonatomic,weak)UIButton *cover;
@property (nonatomic,weak)UIImageView *popView;
@end
@implementation GWPopMenu
-(instancetype)init
{
    if (self =[super init]) {
        UIButton *btn =[[UIButton alloc]init];
        [self addSubview:btn];
//        btn.backgroundColor =[UIColor colorWithWhite:0 alpha:0.3];
        [btn addTarget:self action:@selector(coverOnTouch) forControlEvents:UIControlEventTouchUpInside];
        self.cover =btn;
        
        UIImageView *imageView =[[UIImageView alloc]init];
        imageView.image =[UIImage reSizeWithName:@"popover_background"];
        [self addSubview:imageView];
        self.popView =imageView;
        imageView.alpha =0.8;
        imageView.userInteractionEnabled =YES;
    }
    return self;
}
-(void)coverOnTouch
{
    [self disMiss];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.cover.frame =self.frame;
}
-(void)show
{
    UIWindow *window =[UIApplication sharedApplication].keyWindow;
    self.frame =window.frame;
    self.popView.size =CGSizeMake(140, 220);
    self.popView.x =(self.width-self.popView.width)/2;
    self.popView.y =54;
    
    
    [window addSubview:self];
}
-(void)disMiss
{
    if([self.delegate respondsToSelector:@selector(popMenuDidDismiss:)])
    {
        [self.delegate popMenuDidDismiss:self];
    }
    [self removeFromSuperview];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
